<template>
  <div class="classificationTop">
    <div class="body">
      <div class="title">{{title}}:</div>
      <span :class="{ click: -99 == pointer }" v-on:click="onClick(-1)"
        >全部</span
      >
      <div class="content">
        <span
          v-for="(item, index) in classifications"
          :key="index"
          v-on:click="onClick(index, item)"
          :class="{ click: index == pointer }"
          >{{ item }}</span
        >
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      pointer: -99,
      classifications: [],
    };
  },
  methods: {
    onClick(index, item) {
      this.changeIndex && this.changeIndex(index>=0?index:-1);
      this.getclass&&this.getclass(item);
      if (index >= 0) {
        this.pointer = index;
      } else {
        this.pointer = -99;
      }
    },
    updata() {
      // console.log(this.arr[0]);
      if (this.arr[0].title) {
        let data = this.arr.map((item) => {
          return item.title;
        });
        data.shift();
        console.log(data);
        this.classifications.push(...data);
      } else {
        this.classifications.push(...this.arr);
      }
    },
  },
  props: ["arr", "changeIndex","getclass","title"],
  mounted() {
    this.updata();
  },
};
</script>

<style lang="scss" scoped>
.body {
  margin: 20px 0;
  display: flex;
  .title {
    display: inline-block;
    margin-right: 10px;
    width: 50px;
  }
  .click {
    background-color: rgb(255, 0, 0);
    color: rgb(255, 255, 255);
  }
  span {
    margin-bottom:10px ;
    cursor: pointer;
    display: inline-block;
    padding: 0 7px;
    border-radius: 3px;
    margin-right: 20px;
    height: 25px;
  }
  .content {
    display: flex;
    flex-wrap: wrap;
    width: 1050px;
  }
}
</style>